<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>homework</title>
    <script src="vue.js"></script>
    <style>
        .current {
            color: aqua;
        }
        ul{
            width: 100px;
            height: auto;
            border: 1px solid #ddd;
        }
        li{
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div id="app">
        <ul>
            <li :class="[item.activeClass]" :key="item.id" v-for="(item,index) in movies" @click="setCurrent(index)">{{ item.name }}</li>
        </ul>
    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                movies: [
                    {
                        id: 0,
                        name: 'Superman',
                        activeClass: ''
                    },
                    {
                        id: 1,
                        name: 'Batman',
                        activeClass: ''
                    },
                    {
                        id: 2,
                        name: 'The Flash',
                        activeClass: ''
                    },
                    {
                        id: 3,
                        name: 'Aquaman',
                        activeClass: ''
                    }
                ]
            },
            methods: {
                setCurrent: function(index){
                    this.movies.forEach(element => {
                        if(element.id == index){
                            element.activeClass = 'current';
                        }else{
                            element.activeClass = '';
                        }
                    });
                }
            }
        });
    </script>
</body>

</html>